﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DebugTools
{
    public class DC_Source:Visa
    {

        public DC_Source(string szInsID)
            : base(szInsID)
        {
        }

        public string Set_VC(float Volt, float Curr)
        {
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "SOUR:VOLT " + Volt.ToString() + ";CURR " + Curr.ToString() + "\n";
            this.Write(szCmd);
            if (Volt == 0 && Curr == 0)
                this.ONorOFF(false);
            else
                this.ONorOFF(true);
            szRet = this.Query("SYST:ERR?\n");
            return szRet;
        }

        public double Meas_Volt()
        {
            double dRet = 0.0;
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "MEAS:VOLT?\n";
            szRet = this.Query(szCmd);
            double.TryParse(szRet, out dRet);
            return dRet;
        }

        public double Meas_Curr()
        {
            double dRet = 0.0;
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "MEAS:CURR?\n";
            szRet = this.Query(szCmd);
            double.TryParse(szRet, out dRet);
            return dRet;
        }

        public double Meas_Power()
        {
            double dRet = 0.0;
            string szCmd, szRet;
            szCmd = "*CLS\n";
            this.Write(szCmd);
            szCmd = "MEAS:POW?\n";
            szRet = this.Query(szCmd);
            double.TryParse(szRet, out dRet);
            return dRet;
        }

        public void ONorOFF(bool NF)
        {
            this.Write("*CLS\n");
            this.Write(NF ? "CONF:OUTP ON\n" : "CONF:OUTP OFF\n");
        }
    }
}
